using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ObjectPlacer : MonoBehaviour
{
    // [SerializeField] private List<GameObject> placedGameObjects = new();

    private Dictionary<int, GameObject> placedGameObjectsDic = new Dictionary<int, GameObject>();

    private int seirId;

    private int SeirId
    {
        get
        {
            if (seirId > Int32.MaxValue)
            {
                seirId = 0;
            }

            seirId++;
            return seirId;
        }
    }

    public int PlaceObject(GameObject prefab, Vector3 position)
    {
        GameObject newObject = Instantiate(prefab, transform);

        newObject.transform.position = position;

        placedGameObjectsDic.Add(SeirId, newObject);
        // placedGameObjects.Add(newObject);
        return seirId;
    }

    internal void RemoveObjectAt(int gameObjectIndex)
    {
        // if (placedGameObjects.Count > gameObjectIndex && placedGameObjects[gameObjectIndex] != null)
        // {
        //     // Destroy(placedGameObjects[gameObjectIndex]);
        //     placedGameObjects[gameObjectIndex] = null;
        // }

        if (placedGameObjectsDic.ContainsKey(gameObjectIndex))
        {
            Destroy(placedGameObjectsDic[gameObjectIndex]);
            placedGameObjectsDic.Remove(gameObjectIndex);
        }
    }
}